package com.zjj.lbw.ai;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.output.Response;

public class ChatModelTest {
    public static void main(String[] args) {
        // ChatLanguageModel model = OpenAiChatModel.withApiKey("demo"); 这种写法目前会报错，只能用gpt-4o-mini模型
        // Only gpt-4o-mini model is available for demonstration purposes
        ChatLanguageModel model = OpenAiChatModel.builder().modelName("gpt-4o-mini").apiKey("demo").build();
//        String result = model.generate("你是谁");
//        System.out.println(result);

        // 底层实现，是两个独立聊天，无法记录上下文
//        model.generate("我是子坚君");
//        String result = model.generate("我叫什么名字");
//        System.out.println(result);

        // 实现上下, 每次把之前消息传进去
        UserMessage userMessage1 = UserMessage.from("我是子坚君");
        Response<AiMessage> response1 = model.generate(userMessage1);
        System.out.println(response1.content());

        UserMessage userMessage2 = UserMessage.from("我叫什么名字");
        Response<AiMessage> response2 = model.generate(userMessage1, response1.content(), userMessage2);
        System.out.println(response2.content().text());


    }
}
